package com.pptiku.jh.routerdemo;

import android.app.Application;

import com.alibaba.android.arouter.launcher.ARouter;
import com.kingja.loadsir.core.LoadSir;
import com.pptiku.jh.routerdemo.dagger2.components.AppComponent;
import com.pptiku.jh.routerdemo.dagger2.components.DaggerAppComponent;
import com.pptiku.jh.routerdemo.dagger2.module.AppModule;
import com.pptiku.jh.routerdemo.loadsir.EmptyCallback;
import com.pptiku.jh.routerdemo.loadsir.EmptyCollectionCallback;
import com.pptiku.jh.routerdemo.loadsir.LoadingCallback;
import com.pptiku.jh.routerdemo.loadsir.PlaceholderCallback;
import com.pptiku.jh.routerdemo.loadsir.RetryCallback;
import com.tencent.smtt.sdk.QbSdk;

/**
 * Created by ytf on 2018/5/31.
 * Description:
 */
public class App extends Application
{
    private AppComponent appComponent;

    private static App instance;

    @Override
    public void onCreate()
    {
        super.onCreate();
        instance = this;
        ARouter.openLog();
        ARouter.openDebug();
        ARouter.init(this);

        LoadSir.beginBuilder()
                .addCallback(new LoadingCallback())
                .addCallback(new EmptyCallback())
                .addCallback(new EmptyCollectionCallback())
                .addCallback(new PlaceholderCallback())
                .addCallback(new RetryCallback())
                .setDefaultCallback(PlaceholderCallback.class)
                .commit();
        initX5WebviewCore();

        appComponent = DaggerAppComponent.builder()
                .appModule(new AppModule(this))
                .build();
    }

    private void initX5WebviewCore()
    {
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback()
        {

            @Override
            public void onViewInitFinished(boolean arg0)
            {
            }

            @Override
            public void onCoreInitFinished()
            {
            }
        };
        //x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);
    }

    public AppComponent getAppComponent()
    {
        return appComponent;
    }

    public static App getApp()
    {
        return instance;
    }
}
